package Arrays;

import java.util.HashSet;
import java.util.Set;

public class _268_MissingNumber {
    //use hashset, a little slow
    public int missingNumber(int[] nums) {
        Set<Integer> numSet = new HashSet<Integer>();
        for(int i=0;i<nums.length;i++) {
            numSet.add(nums[i]);
        }
        for(int i=0;i<nums.length;i++) {
            if (!numSet.contains(i)) {
                return i;
            }
        }
        return nums.length;
    }

    //direct calculate
    public int missingNumber1(int[] nums) {
        int total = 0;
        for(int i=0;i<=nums.length;i++) {
            total+=i;
        }
        for (int n : nums) {
            total-=n;
        }
        return total;
    }
}
